package com.jia.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jia.shop.entity.ShopType;
import com.jia.shop.service.ShopTypeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (ShopType)表控制层
 *
 * @author makejava
 * @since 2024-10-03 20:14:06
 */
@RestController
@RequestMapping("shop/type")
public class ShopTypeController {
    /**
     * 服务对象
     */
    @Resource
    private ShopTypeService shopTypeService;

    /**
     * 分页查询
     *
     * @param shopType 筛选条件
     * @param page     分页对象
     * @return 查询结果
     */
    @GetMapping("/page")
    public ResponseEntity<Page<ShopType>> queryByPage(ShopType shopType, Page page) {
        return ResponseEntity.ok(this.shopTypeService.queryByPage(shopType, page));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<ShopType> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.shopTypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param shopType 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ShopType> add(@RequestBody ShopType shopType) {
        return ResponseEntity.ok(this.shopTypeService.insert(shopType));
    }

    /**
     * 编辑数据
     *
     * @param shopType 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ShopType> edit(@RequestBody ShopType shopType) {
        return ResponseEntity.ok(this.shopTypeService.update(shopType));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.shopTypeService.deleteById(id));
    }

}

